//
//  HitTestView.swift
//  
//
//  Created by bo wang on 2020/9/12.
//  Copyright © 2020 wangbo. All rights reserved.
//

import UIKit

/// 所有点击到本身的事件全部透传。点击到子view的事件不透传
class HitTestView: UIView {
    
    /// 是否启用透传。为 false 时关闭透传事件功能。默认为true。
    @IBInspectable var passthrough: Bool = true
    
    override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
        let view = super.hitTest(point, with: event)
        return (passthrough && view === self) ? nil : view
    }
}
